package com.itheima.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Service;

import com.itheima.dao.BirdMapper;
import com.itheima.po.Bird;
import com.itheima.vo.BirdVo;

@Service
public class BirdServiceImpl implements BirdService{
	@Autowired
	private BirdMapper birdMapper;
	
	public List<Bird> findBirdAll(){   
		List<Bird> birdList = this.birdMapper.findBirdAll();
		return birdList;
	}
	
	public List<BirdVo> findBirdVoAll(){
		List<Bird> birdList = this.birdMapper.findBirdAll();
		List<BirdVo> birdVoList = new ArrayList<BirdVo>();
		//添加转换逻辑
		String str;
		for (Bird bird : birdList) {
			BirdVo birdVo=new BirdVo();
			birdVo.setBird(bird);
			if(bird.getType().equals("乌鸦")) {str="https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=812022259,4203763086&fm=26&gp=0.jpg";}
			else if(bird.getType().equals("凤凰")) {str="https://ss0.baidu.com/94o3dSag_xI4khGko9WTAnF6hhy/baike/s=220/sign=407eea970cf3d7ca08f63874c21ebe3c/ac345982b2b7d0a2d4a8a934cbef76094b369a32.jpg";}
			else {str="https://ss2.baidu.com/-vo3dSag_xI4khGko9WTAnF6hhy/baike/pic/item/21a4462309f79052bd897cfb06f3d7ca7acbd564.jpg";}
			birdVo.setUrl(str);
			birdVoList.add(birdVo);
		}
		return birdVoList;
	}
	
	public List<Bird> findBirdByType(){   
		List<Bird> birdList = this.birdMapper.findBirdByType();
		return birdList;
	}
	public List<BirdVo> findBirdVoByType(){
		List<Bird> birdList = this.birdMapper.findBirdByType();
		List<BirdVo> birdVoList = new ArrayList<BirdVo>();
		//添加转换逻辑
		String str;
		for (Bird bird : birdList) {
			BirdVo birdVo=new BirdVo();
			birdVo.setBird(bird);
			if(bird.getType().equals("乌鸦")) {str="https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=812022259,4203763086&fm=26&gp=0.jpg";}
			else if(bird.getType().equals("凤凰")) {str="https://ss0.baidu.com/94o3dSag_xI4khGko9WTAnF6hhy/baike/s=220/sign=407eea970cf3d7ca08f63874c21ebe3c/ac345982b2b7d0a2d4a8a934cbef76094b369a32.jpg";}
			else {str="https://ss2.baidu.com/-vo3dSag_xI4khGko9WTAnF6hhy/baike/pic/item/21a4462309f79052bd897cfb06f3d7ca7acbd564.jpg";}
			birdVo.setUrl(str);
			birdVoList.add(birdVo);
		}
		
		
		return birdVoList;
	}
}


